//
//  FoodDetailsViewController.m
//  Project----A
//
//  Created by dlios on 15-6-19.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "FoodDetailsViewController.h"

@interface FoodDetailsViewController ()

@end

@implementation FoodDetailsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor greenColor];
    FoodDetailsView *foodView = [[FoodDetailsView alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
    [self.view addSubview:foodView];
    foodView.movie = self.movie;
    foodView.mydelegate = self;//协议5
    UIImage *image = [UIImage imageNamed:@"btn_nav_share@2x.png"];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithImage:image style:UIBarButtonItemStylePlain target:self action:@selector(buttonRight:)];
    self.navigationItem.rightBarButtonItem.tintColor = [UIColor blackColor];
   // [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(doFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
    self.navigationItem.title = @"同步视频厨房";
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"iconfont-fanhui.png"] style:UIBarButtonItemStylePlain target:self action:@selector(doFinished:)];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor blackColor];
//    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"iconfont-fanhui.png"] style:UIBarButtonItemStylePlain target:self action:@selector(doFinished:)];
}
-(void)buttonRight:(UITabBarItem *)butt
{
    /*@property(nonatomic,assign)BOOL panduan;
  +(instancetype)shareDataBaseHandle;
  #pragma 打开数据库;
  -(void)openDB;
  #pragma 创建表
  -(void)createTable;
  #pragma 插入数据
  -(void)insertMovie:(Movie *)mov;
  #pragma 删除
  -(void)deleteTable:(NSString *)name;
  #pragma 查询
  -(NSMutableArray *)selectAllMovie;
  #pragma 删除表
  -(void)dropTable;
*/
    [[DataBaseHandle shareDataBaseHandle]openDB];//打开数据库
    NSMutableArray *array =  [[DataBaseHandle shareDataBaseHandle]selectAllMovie];//查询
    for (Movie *movie in array) {
        if ([self.movie.name isEqualToString:movie.name]) {
           
            UIAlertView *uialert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"已经收藏过!" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
            [uialert show];
            return;
        }
    }
    

    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"是否收藏?" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"取消", nil];
    [alert show];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 0) {
        
        [[DataBaseHandle shareDataBaseHandle]openDB];//打开数据库
        [[DataBaseHandle shareDataBaseHandle]createTable];//创建表
        [[DataBaseHandle shareDataBaseHandle]insertMovie:self.movie];//插入
        
        
    }
    
    
}

-(void)FoodMater:(NSInteger)buttonnumber{

    if (buttonnumber ==1) {
#pragma 材料页面
        MaterViewController *mater = [[MaterViewController alloc]init];
        [self.navigationController pushViewController:mater animated:YES];
        mater.movie = self.movie;
        
        //NSLog(@"mater.movie.name = %@",mater.movie);
    }else if (buttonnumber ==2)
    {
#pragma 做法页面
        MethodViewController *method = [[MethodViewController alloc]init];
        [self.navigationController pushViewController:method animated:YES];
        method.vegetable_id = self.movie.vegetable_id;
        
        method.movie = self.movie;
        NSLog(@"1111= %@",method.movie.imagePathLandscape);
    }else if (buttonnumber ==3)
    {
#pragma 常识页面
        KnowledgeViewController *knowledge = [[KnowledgeViewController alloc]init];
        [self.navigationController pushViewController:knowledge animated:YES];
        knowledge.movie = self.movie;
        knowledge.vegetable_id = self.movie.vegetable_id;
          NSLog(@"2222= %@",knowledge.movie.imagePathLandscape);
    }else if (buttonnumber ==4)
    {
#pragma 相宜相克
        GoodAandbadViewController *googbad = [[GoodAandbadViewController alloc]init];
        googbad.movie = self.movie;
        NSLog(@"333= %@",googbad.movie.imagePathLandscape);
        [self.navigationController pushViewController:googbad animated:YES];
    
    }else if (buttonnumber ==5)
    {
#pragma 材料视频播放
        
        ViedoViewController *viedoview = [[ViedoViewController alloc]init];
        viedoview.mov = self.movie;
              
        [self.navigationController pushViewController:viedoview animated:YES];
    
    }else if (buttonnumber ==6)
#pragma 制作过程视频
    {
        ProessViewController *proess = [[ProessViewController alloc]init];
        proess.movie = self.movie;
        [self.navigationController pushViewController:proess animated:YES];
    }

}

-(void)doFinished:(id)sender
{
    [[NSNotificationCenter defaultCenter ]removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
    [self.Player.view removeFromSuperview];
    [self.Player release];
    self.Player  = nil;
    [self.navigationController popViewControllerAnimated:YES];//视频
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
